package org.activequant.core.domainmodel.data;

import java.io.Serializable;
import java.util.List;

import org.activequant.core.domainmodel.SeriesSpecification;
import org.activequant.core.types.TimeStamp;
import org.activequant.util.exceptions.ValueNotFoundException;
import org.activequant.util.tools.ArrayUtils;

/**
 * A TimeSeries(ArrayList subclass) whose elements are TickerNews objects.<br/>
 * Holds the following inherited/associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>seriesSpecification(SeriesSpecification)</li>
 * <li>inherited list of elements (List&lt;TickerNews&gt;)</li>
 * </ul>
 *  @author dmisev
 */
	public class TickerNewsSeries extends TimeSeries<TickerNews> implements Serializable {

		private static final long serialVersionUID = -3722093387498618030L;
		
	    /**
	     * an empty TickerNewsSeries constructor.
	     */
	    public TickerNewsSeries() {
	    	
	    }

	    /**
	     * constructs  a TickerNewsSeries(ArrayList and TimeSeries subclass) using the given tickerNews(List&lt;TickerNews&gt;) to set its TickerNews elements.
	     * @param tickerNews
	     */
	    public TickerNewsSeries(List<TickerNews> tickerNews) {
	    	super(tickerNews);
	    }
	    /**
	     * Constructs a TickerNewsSeries(ArrayList and TimeSeries subclass) using the given spec(SeriesSpecification) and tickerNews(List&lt;TickerNews&gt;) to set its associated 
		 * seriesSpecification(SeriesSpecification) and its TickerNews elements.
	     * @param spec
	     * @param tickerNews
	     */
	    public TickerNewsSeries(SeriesSpecification spec, List<TickerNews> tickerNews) {
	    	super(tickerNews);
	    	setSeriesSpecification(spec);
	    }
	    
	    
	    /**
	     * constructs a TickerNewsSeries(ArrayList and TimeSeries subclass) using the given tickerNews(TickerNews...) to set its TickerNews elements.
	     * @param tickerNews
	     */
	    public TickerNewsSeries(TickerNews... tickerNews) {
	    	this(ArrayUtils.asList(tickerNews));
	    }
	    /**
	     * Constructs a TickerNewsSeries(ArrayList and TimeSeries subclass) using the given spec(SeriesSpecification) and tickerNews(TickerNews...) to set its associated 
		 * seriesSpecification(SeriesSpecification) and its TickerNews elements.
	     * @param spec
	     * @param tickerNews
	     */
	    public TickerNewsSeries(SeriesSpecification spec, TickerNews... tickerNews) {
	    	this(tickerNews);
	    	setSeriesSpecification(spec);
	    }
	    /**
	     * Sets the elements of this TickerNewsSeries(ArrayList and TimeSeries subclass) with the given tickerNews(TickerNews...).
	     * @param tickerNews
	     */
	    public void setTickerNews(TickerNews... tickerNews) {
	    	setTickerNews(ArrayUtils.asList(tickerNews));
	    }
	    /**
	     * Sets the elements of this TickerNewsSeries(ArrayList and TimeSeries subclass) with the given tickerNews(List&lt;TickerNews&gt;).
	     * @param tickerNews
	     */
	    public void setTickerNews(List<TickerNews> tickerNews) {
	    	clear();
	    	addAll(tickerNews);
	    }
	    /**
	     * returns a TickerNews[] array containing the elements of this TickerNewsSeries(ArrayList and TimeSeries subclass)
	     * @return
	     */
	    public TickerNews[] getTickerNews() {
	    	return ArrayUtils.asArray(this, TickerNews.class);
	    }
		
	    /**
	     * clone this TickerNewsSeries instance.
	     * @return cloned object
	     */
		public TickerNewsSeries clone() {
			TickerNews[] clonedTickerNews = new TickerNews[size()];
			TickerNews[] tickerNews = toArray(new TickerNews[]{});
			for(int i = 0; i < tickerNews.length; i++) {
				clonedTickerNews[i] = tickerNews[i].clone();
			}
			TickerNewsSeries clone = new TickerNewsSeries(seriesSpecification, clonedTickerNews);
			return clone;
		}
		/**
		 * returns a TickerNewsSeries containing the TickerNews elements whose TimeStamps are within(inclusive) the given start-end(TimeStamp) interval
		 */
	    public TickerNewsSeries getTimeFrame(TimeStamp start, TimeStamp end) {
	    	return (TickerNewsSeries) super.getTimeFrame(start, end);
	    }
		/**
		 * returns a TickerNewsSeries containing the TickerNews elements within(inclusive) the given start-end(int) index interval
		 */
		public TickerNewsSeries subList(int start, int end) throws ValueNotFoundException {
			return (TickerNewsSeries) super.subList(start, end);
		}
		/**
		 * returns a TickerNewsSeries containing the TickerNews elements whose TimeStamps are within(inclusive) the given start-end(TimeStamp) interval
		 */
		public TickerNewsSeries subList(TimeStamp start, TimeStamp end) throws ValueNotFoundException {
			return (TickerNewsSeries) super.subList(start, end);
		}		
		
	}